%% @doc パス設定のテスト
%%
-module(t_path).
-import(templ, [init/1,process/1,process_file/1,set_path/1,append_path/1,get_path/0]).

-include_lib("eunit/include/eunit.hrl").

process_file_test_() ->
	init([{"module",erlang}, 
		  {"l2a",list_to_atom}, {"l2i",list_to_integer},
		  {"string",[{"module",string}, {"substr",substr}]},
		  {"greetings","Hello {user}"}, {"user","{title} Joe"}, {"title", "Mr."},
		  {"jgreetings","こんにちは、\{juser\} 様"}, {"juser","山田太郎"}]),

	[
	 ?_assertMatch([],
				   get_path()),
	 % カレントディレクトリ
	 ?_assertMatch("Welcome! Hello Mr. Joe!",
				   process(process(process_file("test.tmpl")))),
	 ?_assertMatch("こんにちは、山田太郎 様！",
	 			   process(process_file("../tmp/test.tmpl"))),
	 ?_assertMatch("Welcome! Hello Mr. Joe!",
				   process(process(process_file("./test.tmpl")))),

	 ?_assertMatch(ok,
				   append_path("../tmp")),
	 ?_assertMatch("Welcome! Hello Mr. Joe!",
				   process(process(process_file("test.tmpl")))),
	 ?_assertMatch(["../tmp"],
				   get_path()),

	 ?_assertMatch(ok,
				   set_path("../tmp")),
	 ?_assertMatch("Welcome! Hello Mr. Joe!",
	 			   process(process(process_file("test.tmpl")))),
	 ?_assertMatch("hoge\nzero123four\n", 
	 		   process(process_file("hoge/hoge.tmpl"))),

	 ?_assertMatch(ok,
				   set_path([])),
	 ?_assertThrow({{templ,enoent},"hoge.tmpl"}, 
				   process_file("hoge.tmpl")),

	 ?_assertMatch(ok,
	 		   append_path(["../tmp", "../tmp/hoge"])),
	 ?_assertMatch("hogefoo", 
	 		   process(process_file("hoge.tmpl"))),
	 %?_assertThrow({{templ,enoent},"./hoge.tmpl"}, 
	 %			   process_file("./hoge.tmpl")),
	 ?_assertMatch("hogefoo", 
	 		   process(process_file("./hoge.tmpl"))),
	 ?_assertMatch("hoge\nzero123four\n", 
	 		   process(process_file("hoge/hoge.tmpl"))),

	 ?_assertMatch(ok,
				   set_path([".", "../tmp/hoge", "../tmp"])),
	 ?_assertMatch("hoge\nzero123four\n",
				   process(process(process_file("hoge.tmpl")))),

	 ?_assertMatch([".", "../tmp/hoge", "../tmp"],
				   get_path())
	].
